﻿using System;
using System.Collections.Generic;

namespace SimpleFS.Core.Implementations
{
    public abstract class AbstractFile : IFile
    {
        protected IFile internalObject;

        public AbstractFile(IFile internalObject)
        {
            this.internalObject = internalObject;
        }

        #region IFile Members

        public virtual System.IO.Stream Read()
        {
            return this.internalObject.Read();
        }

        public virtual void Write(System.IO.Stream stream)
        {
            this.internalObject.Write(stream);
        }

        #endregion

        #region IFileSystemObject Members

        public virtual string Name
        {
            get { return this.internalObject.Name; }
        }

        public virtual DateTime LastModifiedTime
        {
            get { return this.internalObject.LastModifiedTime; }
        }

        public virtual Dictionary<string, string> Attributes
        {
            get { return this.internalObject.Attributes; }
        }

        public virtual IDirectory ParentDirectory
        {
            get { return this.internalObject.ParentDirectory; }
        }

        public virtual void Copy(IFileSystemObject target)
        {
            IFile targetFile = target as IFile;
            
            System.IO.Stream stream = this.internalObject.Read();
            targetFile.Write(stream);

            stream.Close();
        }

        public virtual void Move(IFileSystemObject target)
        {
            this.Copy(target);
            this.Delete();
        }

        public virtual void Delete()
        {
            this.internalObject.Delete();
        }

        public virtual bool Exists()
        {
            return this.internalObject.Exists();
        }

        public virtual void Rename(string newName)
        {
            this.internalObject.Rename(newName);
        }

        public virtual void Close()
        {
            this.internalObject.Close();
        }

        #endregion

        #region IFile Members


        public string Extension
        {
            get { throw new NotImplementedException(); }
        }

        #endregion

        #region IFileSystemObject Members


        public int Size
        {
            get { throw new NotImplementedException(); }
        }

        #endregion
    }
}
